﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace ArgusPCLib
{
	/// <summary>
	/// Defines Extension-Methods for classes in the <see cref="System.Xml"/> namespace.
	/// </summary>
	public static class SystemXmlExtensions
	{
		public static void WriteElementObject(this XmlWriter xmlWriter, string localName, object value)
		{
			List<object> parents = new List<object>();
			xmlWriter.WriteStartElement(localName);
			if (value != null)
			{
				IEnumerable enumerable = value as IEnumerable;
				if (enumerable != null && !(value is string))
				{
					foreach (Object obj in enumerable)
					{
						xmlWriter.WriteElementObject("Item", obj);
					}
				}
				else
					xmlWriter.WriteValue(value.ToStringInvariant());
			}
			xmlWriter.WriteEndElement();
		}
	}
}
